package kr.pe.johnkim.checkmileage.mobile.rest.controller;

import kr.pe.johnkim.checkmileage.mobile.domain.CheckMileageBusinessKind;
import kr.pe.johnkim.checkmileage.mobile.rest.service.CheckMileageBusinessKindService;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

/**
 * Check Mileage 업종 관련 Controller 클래스 이다.
 *
 * @author : johnkim <cale9797@gmail.com / Bettersoft, Inc.>
 * @date: 12. 10. 11.
 */

@Controller
@Path("/checkMileageBusinessKindController")
public class CheckMileageBusinessKindController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(CheckMileageBusinessKindController.class);

    @Autowired
    private CheckMileageBusinessKindService checkMileageBusinessKindService = null;

    /**
     * 사용자 검색을 위한 업종 목록을 가져 온다.
     *
     * @param is
     * @return
     * @throws Exception
     */
    @POST
    @Path("/selectBusinessKindList")
    @Consumes({"application/json", "application/xml"})
    @Produces({"application/json", "application/xml"})
    public List<CheckMileageBusinessKind> selectBusinessKindList(InputStream is) throws Exception {
        logger.info("selectMerchantMemberMileageList");

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = br.readLine();

        logger.info("line : {}", line);

        JSONObject jsonBusinessKind = new JSONObject(line);
        JSONObject jsonBusinessKind2 = jsonBusinessKind.getJSONObject("checkMileageBusinessKind");

        CheckMileageBusinessKind parameterBusinessKind = new CheckMileageBusinessKind();

        parameterBusinessKind.setCountryCode(jsonBusinessKind2.getString("countryCode"));
        parameterBusinessKind.setLanguageCode(jsonBusinessKind2.getString("languageCode"));
        parameterBusinessKind.setActivateYn(jsonBusinessKind2.getString("activateYn"));

        return checkMileageBusinessKindService.selectBusinessKindList(parameterBusinessKind);
    }
}
